package com.antoco.operation.bigscreen.model.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.persistence.*;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.*;

/**
 * 传感器
 */
@Entity
@Data
@Table(name = "sensor")
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EntityListeners(AuditingEntityListener.class)
@Accessors(chain = true)
public class Sensor implements AbstractEntity<Long> , Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    /**
     * 传感器图片关联
     */
    @JoinColumn(name = "sensor_id")
    @OneToMany(cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
    private List<SensorImg> sensorImgs = new ArrayList<>();

    /**
     * 设备大类
     * 设备大类 1代表水质，2代表水量
     */
    @Column(name = "dev_big_type")
    private String devBigType = "2";

    /**
     * 设备大类名称
     */
    @Column(name = "dev_big_type_name")
    private String devBigTypeName = "水质";

    /**
     * 设备类型
     */
    @Column(name = "dev_type")
    private String devType = "1";

    /**
     * 设备类型名称
     */
    @Column(name = "dev_type_name")
    private String devTypeName = "电子水尺";

    /**
     * 设备名称
     */
    @Column(name = "name")
    private String name;

    /**
     * 地理位置名称
     */
    @Column(name = "gis_name")
    private String gisName;

    /**
     * 地理位置经度
     */
    @Column(name = "gis_jindu")
    private String gisJindu;

    /**
     * 地理位置纬度
     */
    @Column(name = "gis_weidu")
    private String gisWeidu;

    /**
     * 设备状态
     */
    @Column(name = "state")
    private String state = "";

    /**
     * 设备状态名称
     */
    @Column(name = "state_name")
    private String stateName = "正常";

    /**
     * 信号情况
     */
    @Column(name = "xinhao")
    private String xinhao = "1";

    /**
     * 信号情况名称
     */
    @Column(name = "xinhao_name")
    private String xinhaoName = "正常";

    /**
     * 调试状态
     */
    @Column(name = "tiaosi")
    private String tiaosi = "2";

    /**
     * 调试状态名称
     */
    @Column(name = "tiaosi_name")
    private String tiaosiName = "否";

    /**
     * 安装时间
     */
    @Column(name = "build_time")
    private String buildTime;

    /**
     * 超声波水位
     */
    @Column(name = "caosenbo_suiwei")
    private String caosenboSuiwei = "0";

    /**
     * 压力水位
     */
    @Column(name = "yali_suiwei")
    private String yaliSuiwei = "0";

    /**
     * 离水底高度
     */
    @Column(name = "hight_for_bottom")
    private String hightForBottom = "0";

    /**
     * 剩余电量
     */
    @Builder.Default
    @Column(name = "senyu_dianlian")
    private String senyuDianlian = "1";

    /**
     * 值类型名称
     */
    @Column(name = "val_type")
    private String valType;

    /**
     * 值单位名称
     */
    @Column(name = "val_type_name")
    private String valTypeName;

    /**
     * 预警阀值
     */
    @Builder.Default
    @Column(name = "alarm_limit_val")
    private String alarmLimitVal = "0";

    /**
     * 告警阀值
     */
    @Builder.Default
    @Column(name = "warn_limit_val")
    private String warnLimitVal = "0";

    /**
     * 最新值
     */
    @Column(name = "newest_val")
    private String newestVal;

    /**
     * 最新通信时间
     */
    @Column(name = "newest_report_time")
    private String newestReportTime;

    /**
     * 最新通讯标识（预留）
     */
    @Column(name = "newest_report_id")
    private Long newestReportId;

    /**
     * 警告总次数
     */
    @Column(name = "alert_all_num")
    private Integer alertAllNum = 0;

    /**
     * 预警总次数
     */
    @Column(name = "aleam_num")
    private Integer aleamNum = 0;

    /**
     * 告警总次数
     */
    @Column(name = "warn_num")
    private Integer warnNum = 0;

    /**
     * 通信总次数
     */
    @Column(name = "report_num")
    private Integer reportNum = 0;

    /*
     * 今天的总报告数
     */
    @Column(name = "report_num_today")
    private Integer reportNumToday = 0;

    /**
     * 历史最小值
     */
    @Column(name = "min_val")
    private String minVal = "0";

    /**
     * 历史最大值
     */
    @Column(name = "max_val")
    private String maxVal = "0";

    /**
     * 历史平均值
     */
    @Column(name = "ave_val")
    private Double aveVal = 0.0;

    /**
     * 当天最小值
     */
    @Column(name = "this_min_val")
    private String thisMinVal = "0";

    /**
     * 上一日最小值
     */
    @Column(name = "prev_min_val")
    private String prevMinVal = "0";

    /**
     * 当天最小值变化趋势
     */
    @Column(name = "this_min_chg_qusi")
    private String thisMinChgQusi;

    /**
     * 上一日最小值变化趋势
     */
    @Column(name = "prev_min_chg_qusi")
    private String prevMinChgQusi;

    /**
     * 当天最小值变化率
     */
    @Column(name = "this_min_chg_lv")
    private String thisMinChgLv = "0";

    /**
     * 当天最大值
     */
    @Column(name = "this_max_val")
    private String thisMaxVal = "0";

    /**
     * 上一日最大值
     */
    @Column(name = "prev_max_val")
    private String prevMaxVal = "0";

    /**
     * 当天最大值变化趋势
     */
    @Column(name = "this_max_chg_qusi")
    private String thisMaxChgQusi;

    /**
     * 上一日最大值变化趋势
     */
    @Column(name = "prev_max_chg_qusi")
    private String prevMaxChgQusi;

    /**
     * 当天最大值变化率
     */
    @Column(name = "this_max_chg_lv")
    private String thisMaxChgLv = "0";

    /**
     * 当天平均值
     */
    @Column(name = "this_ave_val")
    private String thisAveVal = "0";

    /**
     * 上一日平均值
     */
    @Column(name = "prev_ave_val")
    private String prevAveVal = "0";

    /**
     * 当天平均值变化趋势
     */
    @Column(name = "this_ave_chg_qusi")
    private String thisAveChgQusi;

    /**
     * 上一日平均值变化趋势
     */
    @Column(name = "prev_ave_chg_qusi")
    private String prevAveChgQusi;

    /**
     * 当天平均值变化率
     */
    @Column(name = "this_ave_chg_lv")
    private String thisAveChgLv = "0";

    /**
     * 创建时间
     */
    @Column(name = "gen_time")
    @CreatedDate
    private Timestamp genTime;

    /**
     * 记录状态
     */
    @Column(name = "rec_state")
    private String recState;
}
